#include "friends.h"
#include "friend.h"
#include <QScrollArea>
#include "interface_control.h"
#include "client_connet.h"

Friends::Friends()
{
    this->resize(800,800);
    qDebug()<<"断点5";
    QScrollArea* scl = new QScrollArea(this);
    scl->setGeometry(0,0,800,800);
    QString styleSheet = "QScrollBar:vertical {"
                         "    width: 5px; /* 设置一个很小的宽度 */"
                         "    background: transparent; /* 设置背景透明 */"
                         "    border: none; /* 移除边框 */"
                         "    margin: 0px; /* 移除外边距 */"
                         "    padding: 0px; /* 移除内边距 */"
                         "    /* 这里可以添加滚动条滑块（handle）的样式 */"
                         "    QScrollBar::handle:vertical {"
                         "        background: rgba(255, 255, 255, 128); /* 半透明滑块背景 */"
                         "        min-height: 20px; /* 设置滑块的最小高度 */"
                         "        border-radius: 2px; /* 设置滑块边框圆角 */"
                         "    }"
                         "}"
                         "QScrollBar:horizontal {"
                         "    height: 5px; /* 设置水平滚动条的高度 */"
                         "    background: transparent; /* 设置背景透明 */"
                         "    border: none; /* 移除边框 */"
                         "    margin: 0px; /* 移除外边距 */"
                         "    padding: 0px; /* 移除内边距 */"
                         "    /* 这里可以添加水平滚动条滑块的样式 */"
                         "}";
    scl->setStyleSheet(styleSheet);

    friends_widget = new QWidget(this);
    friends_widget->move(0,0);

    friends_vl = new QVBoxLayout(friends_widget);
    friends_vl->setSpacing(0);

    scl->setWidget(friends_widget);
    int num = Client_connet::Get_Connet()->frarr.size();
   //初始化主界面与聊天界面
    qDebug()<<"数组长度:"<<num;
    for(int i = 0; i < num; ++i)
    {
        qDebug()<<"初始化好友："<<i;
        AddFriend(Client_connet::Get_Connet()->frarr[i].friendloginid,Client_connet::Get_Connet()->frarr[i].name,Client_connet::Get_Connet()->frarr[i].FriendGroups);
        //为好友创对应界面并加入map
//        GroupChat* gr = new GroupChat();
//        gr->setMfrend(Client_connet::Get_Connet()->frarr[i]);//传入对应的好友
//        Interface_Control::getControlptr()->setGro_map((Client_connet::Get_Connet()->frarr[i].friendloginid),gr);
    }
}

void Friends::AddFriend(QString id,QString name,int gid)
{
    fris += 100;
    friends_widget->resize(790,fris);
    Friend *fri1 = new Friend(friends_widget,id,name,gid);
    friends_vl->addWidget(fri1);

    //将创建的对象加入到map
    frientds f;
    f.friendloginid = id;
    f.name = name;
    f.FriendGroups = gid;
    GroupChat* gr = new GroupChat();
    gr->setMfrend(f);//传入对应的好友
    Interface_Control::getControlptr()->setGro_map(f.friendloginid,gr);
}

